﻿// Operations and events related to enabling or disabling an element
define([
    'Wjs/Wjs'
],
function () {
    'use strict';

    return Wjs.defineOnce({

        type: 'Disableable',

        internal: {

            listeners: {

                onDomElementCreated: function () {

                    if (this.disabled) { // If the element is initially disabled then disable it

                        this.disable();

                        delete this.disabled;
                    }
                }
            }
        },

        enable: function () {

            if (this.isRendered()) {

                this.getDomElement().disabled = false;
            }
            else {

                this.disabled = false;
            }

            return this;
        },

        disable: function () {

            if (this.isRendered()) {

                this.getDomElement().disabled = true;
            }
            else {

                this.disabled = true;
            }

            return this;
        },

        isDisabled: function () {

            if (this.isRendered()) {

                return this.getDomElement().disabled == true;
            }
            else {

                return this.disabled == true;
            }
        }

    });

});